package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.AdminOrderServiceImpl;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单管理接口")
@RestController("AdminOrderController")
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private AdminOrderServiceImpl adminOrderService;

    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        return Result.success(adminOrderService.conditionSearch(ordersPageQueryDTO));
    }

    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result<String> delivery(@PathVariable Long id) {
        return Result.success(adminOrderService.delivery(id));
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id) {
        return Result.success(adminOrderService.details(id));
    }


    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result<String> confirm(@RequestBody Orders orders) {
        return Result.success(adminOrderService.confirm(orders));
    }

    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result<String> rejection(@RequestBody Orders orders) {
        return Result.success(adminOrderService.rejection(orders));
    }

    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result<String> complete(@PathVariable Long id) {
        return Result.success(adminOrderService.complete(id));
    }

    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics() {
        return Result.success(adminOrderService.statistics());
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result<String> cancel(@RequestBody Orders orders) {
        return Result.success(adminOrderService.cancel(orders));
    }

}
